package com.zyx.utils;

import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.function.Predicate;

/**
 * @author Yaxi.Zhang
 * @since 2022/10/6 23:51
 */
public class PredicateUtils {

    public static Predicate<String> mergePaths(List<Predicate<String>> includePaths,
                                               List<Predicate<String>> excludePaths) {
        Predicate<String> incPredicate = CollectionUtils.isEmpty(includePaths) ? (str) -> true :
                includePaths.stream().reduce((str) -> false, Predicate::or);
        Predicate<String> excPredicate = CollectionUtils.isEmpty(includePaths) ? (str) -> true :
                excludePaths.stream().reduce((str) -> false, Predicate::or).negate();
        return incPredicate.and(excPredicate);
    }

}
